home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_perl.idb / usr / freeware / catman / p_man / cat3 / File::Find.Z / File::Find
Encoding:
Text File  |  1998-10-28  |  3.4 KB  |  133 lines

  1.  
  2.  
  3.  
  4.      FFFFiiiilllleeee::::::::FFFFiiiinnnndddd((((3333))))   22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))     FFFFiiiilllleeee::::::::FFFFiiiinnnndddd((((3333))))
  5.  
  6.  
  7.  
  8.      NNNNAAAAMMMMEEEE
  9.       find - traverse a file tree
  10.  
  11.       finddepth - traverse a directory structure depth-first
  12.  
  13.      SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  14.           use File::Find;
  15.           find(\&wanted, '/foo','/bar');
  16.           sub wanted { ... }
  17.  
  18.           use File::Find;
  19.           finddepth(\&wanted, '/foo','/bar');
  20.           sub wanted { ... }
  21.  
  22.  
  23.      DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  24.       The first argument to    _f_i_n_d() is either a hash    reference
  25.       describing the operations to be performed for    each file, or
  26.       a code reference.  If    it is a    hash reference,    then the value
  27.       for the key wanted should be a code reference.  This code
  28.       reference is called _t_h_e _w_a_n_t_e_d() _f_u_n_c_t_i_o_n below.
  29.  
  30.       Currently the    only other supported key for the above hash is
  31.       bydepth, in presense of which    the walk over directories is
  32.       performed depth-first.  Entry    point _f_i_n_d_d_e_p_t_h() is a
  33.       shortcut for specifying { bydepth = 1}> in the first
  34.       argument of _f_i_n_d().
  35.  
  36.       The _w_a_n_t_e_d() function    does whatever verifications you    want.
  37.       $File::Find::dir contains the    current    directory name,    and $_
  38.       the current filename within that directory.
  39.       $File::Find::name contains "$File::Find::dir/$_".  You are
  40.       _c_h_d_i_r()'d to $File::Find::dir    when the function is called.
  41.       The function may set $File::Find::prune to prune the tree.
  42.  
  43.       File::Find assumes that you don't alter the $_ variable.  If
  44.       you do then make sure    you return it to its original value
  45.       before exiting your function.
  46.  
  47.       This library is useful for the find2perl tool, which when
  48.       fed,
  49.  
  50.           find2perl    / -name    .nfs\* -mtime +7 \
  51.           -exec    rm -f {} \; -o -fstype nfs -prune
  52.  
  53.       produces something like:
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.      Page 1                        (printed 10/23/98)
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.      FFFFiiiilllleeee::::::::FFFFiiiinnnndddd((((3333))))   22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))     FFFFiiiilllleeee::::::::FFFFiiiinnnndddd((((3333))))
  71.  
  72.  
  73.  
  74.           sub wanted {
  75.           /^\.nfs.*$/ &&
  76.           (($dev,$ino,$mode,$nlink,$uid,$gid) =    lstat($_)) &&
  77.           int(-M _) > 7    &&
  78.           unlink($_)
  79.           ||
  80.           ($nlink || (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_))) &&
  81.           $dev < 0 &&
  82.           ($File::Find::prune =    1);
  83.           }
  84.  
  85.       Set the variable $File::Find::dont_use_nlink if you're using
  86.       AFS, since AFS cheats.
  87.  
  88.       finddepth is just like find, except that it does a depth-
  89.       first    search.
  90.  
  91.       Here's another interesting wanted function.  It will find
  92.       all symlinks that don't resolve:
  93.  
  94.           sub wanted {
  95.           -l &&    !-e && print "bogus link: $File::Find::name\n";
  96.           }
  97.  
  98.  
  99.      BBBBUUUUGGGGSSSS
  100.       There    is no way to make find or finddepth follow symlinks.
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.      Page 2                        (printed 10/23/98)
  130.  
  131.  
  132.  
  133.